Built-in Functions

The Python interpreter has a number of functions built into it that are always available. They are listed here in alphabetical order.
\begin{funcdesc}{abs}{x}
 Return the absolute value of a number. The argument may be a plain
 or long integer or a floating point number.
\end{funcdesc}

\begin{funcdesc}{apply}{function\, args}
The \var{function} argument must be a c...
...rgs})}, since in that case there is always
exactly one argument.)
\end{funcdesc}

\begin{funcdesc}{chr}{i}
 Return a string of one character whose \ASCII{} code i...
...e{ord()}. The argument must be in the range [0..255],
 inclusive.
\end{funcdesc}

\begin{funcdesc}{cmp}{x\, y}
 Compare the two objects \var{x} and \var{y} and re...
...} == \var{y}} and strictly positive if
 \code{\var{x} > \var{y}}.
\end{funcdesc}

\begin{funcdesc}{coerce}{x\, y}
 Return a tuple consisting of the two numeric ar...
...mon type, using the same rules as used by arithmetic
 operations.
\end{funcdesc}

\begin{funcdesc}{compile}{string\, filename\, kind}
 Compile the \var{string} in...
...tements, or \code{'eval'}
 if it consists of a single expression.
\end{funcdesc}

\begin{funcdesc}{delattr}{object\, name}
 This is a relative of \code{setattr}. ...
...var{foobar}')} is equivalent to
 \code{del \var{x}.\var{foobar}}.
\end{funcdesc}

\begin{funcdesc}{dir}{}
 Without arguments, return the list of names in the curr...
...es', 'path', 'stderr', 'stdin', 'stdout']
>>>\end{verbatim}\ecode
\end{funcdesc}

\begin{funcdesc}{divmod}{a\, b}
 Take two numbers as arguments and return a pair...
...as
 \code{(math.floor(\var{a} / \var{b}), \var{a} \%{} \var{b})}.
\end{funcdesc}

\begin{funcdesc}{eval}{s\optional{\, globals\optional{\, locals}}}
 The argument...
...cution of statements is supported by the
 \code{exec} statement.

\end{funcdesc}

\begin{funcdesc}{filter}{function\, list}
Construct a list from those elements o...
...lements of \var{list} that are false (zero or empty) are
removed.
\end{funcdesc}

\begin{funcdesc}{float}{x}
 Convert a number to floating point. The argument may be a plain or
 long integer or a floating point number.
\end{funcdesc}

\begin{funcdesc}{getattr}{object\, name}
 The arguments are an object and a stri...
..., '\var{foobar}')} is equivalent to
 \code{\var{x}.\var{foobar}}.
\end{funcdesc}

\begin{funcdesc}{hasattr}{object\, name}
 The arguments are an object and a stri...
...bject, name)} and
 seeing whether it raises an exception or not.)
\end{funcdesc}

\begin{funcdesc}{hash}{object}
 Return the hash value of the object (if it has o...
...ash value (even if they are of different types, e.g.
 1 and 1.0).
\end{funcdesc}

\begin{funcdesc}{hex}{x}
 Convert a number to a hexadecimal string. The result is a valid
 Python expression.
\end{funcdesc}

\begin{funcdesc}{id}{object}
 Return the \lq identity' of an object. This is an int...
...alue.) (Implementation note: this is the address of the
 object.)
\end{funcdesc}

\begin{funcdesc}{input}{\optional{prompt}}
 Almost equivalent to \code{eval(raw_...
...ay be broken over multiple lines using
 the backslash convention.
\end{funcdesc}

\begin{funcdesc}{int}{x}
 Convert a number to a plain integer. The argument may be a plain or
 long integer or a floating point number.
\end{funcdesc}

\begin{funcdesc}{len}{s}
 Return the length (the number of items) of an object. ...
... be a sequence (string, tuple or list) or a mapping (dictionary).
\end{funcdesc}

\begin{funcdesc}{long}{x}
 Convert a number to a long integer. The argument may be a plain or
 long integer or a floating point number.
\end{funcdesc}

\begin{funcdesc}{map}{function\, list\, ...}
Apply \var{function} to every item ...
...guments may be
any kind of sequence; the result is always a list.
\end{funcdesc}

\begin{funcdesc}{max}{s}
 Return the largest item of a non-empty sequence (string, tuple or
 list).
\end{funcdesc}

\begin{funcdesc}{min}{s}
 Return the smallest item of a non-empty sequence (string, tuple or
 list).
\end{funcdesc}

\begin{funcdesc}{oct}{x}
 Convert a number to an octal string. The result is a valid Python
 expression.
\end{funcdesc}
openfilename  mode  bufsize Return a new file object (described earlier under Built-in Types). The first two arguments are the same as for stdio's fopen(): filename is the file name to be opened, mode indicates how the file is to be opened: 'r' for reading, 'w' for writing (truncating an existing file), and 'a' opens it for appending. Modes 'r+', 'w+' and 'a+' open the file for updating, provided the underlying stdio library understands this. On systems that differentiate between binary and text files, 'b' appended to the mode opens the file in binary mode. If the file cannot be opened, IOError is raised. If mode is omitted, it defaults to 'r'. The optional bufsize argument specifies the file's desired buffer size: 0 means unbuffered, 1 means line buffered, any other positive value means use a buffer of (approximately) that size. A negative bufsize means to use the system default, which is usually line buffered for for tty devices and fully buffered for other files.